﻿<!DOCTYPE html>
<html lang="en">
<head>
    <title>注册</title>
    <!-- Meta tag Keywords -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <!-- Meta tag Keywords -->
    <!-- css files -->
    <link href="./css/style.css" rel="stylesheet" type="text/css" media="all">
    <script src="./jquery/jquery-3.6.0.js"></script>
<body>
<!--header-->
<div class="agileheader">
    <h1></h1>
</div>
<!--//header-->
<!--main-->
<div class="main-w3l">
    <div class="w3layouts-main">
        <h2>用户注册</h2>
        <form action="#" method="post" id="register_form">
            <input placeholder="输入用户名" name="username" id="register_username" type="username"/>
            <input placeholder="输入邮箱" name="email" id="register_email" type="username"/>
            <input placeholder="输入电话号码" name="phone" type="username" id="register_phone"/>
            <input placeholder="输入密码" name="password" type="password" id="register_password"/>
            <input placeholder="确认密码" name="passConfirm" type="password" id="register_passConfirm"/>
            <!--                    <span><input type="checkbox" />记住我</span>-->
            <!--                    <h6><a href="#">忘记密码?</a></h6>-->
            <div class="clear"></div>
            <input type="button" value="注 册" name="register" id="register_button">
        </form>
        <!--                <p>还没有账号 ?<a href="#">立即注册</a></p>-->
    </div>

</div>
<!--//main-->
<!--footer-->
<div class="footer-w3l">
    <p>&copy; Register. All rights reserved | Design by Group8</a></p>
</div>
<!--//footer-->

<script>
    $("#register_button").click(function () {

        let register_username = $("#register_username").val();
        let register_email = $("#register_email").val();
        let register_phone = $("#register_phone").val();
        // let register_passConfirm = $("#register_passConfirm").val();
        let register_password = $("#register_password").val();
        let register_role = "user";
        let register_auth = '1';
        let time = "2022-06-10 10:51:54";
        let datas = {
            email: register_email,
            password: register_password,
            phone: register_phone,
            username: register_username,
            role: register_role,
            auth: register_auth,
            register_time: time
        }
        $.ajax({
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            url: "/user/insert",
            type: "post",
            cache: false,
            data: JSON.stringify(datas),
            datatype: "json",
            success: function (response) {
                alert(register_username);
                console.log("返回：" + response.code);
                if (response.code === 200) {
                    alert("注册成功！");
                    window.location.href = "/login.html";
                }
            },
            error: function (response) {
                console.log("出错返回：" + response);
                alert("1");

            }


        });
    });
</script>


</body>
</html>
